Skip to content

Conversation

@whankinsiv
Copy link
Collaborator

@whankinsiv whankinsiv commented Oct 24, 2025

This PR implements 3 of the 10 remaining account related endpoints described in #256:

  • /accounts/{stake_address}/registrations - Queries historical_accounts_state for registration history, then fetches TxHash values from chain_store using each TxIdentifier to construct the Blockfrost aligned response.
  • /accounts/{stake_address}/delegations - Queries historical_accounts_state for delegation history, resolving TxHash via chain_store.
  • /accounts/{stake_address}/mirs - Queries historical_accounts_state for MIR history, resolving TxHash via chain_store.

Main changes:

  • Registered 3 endpoints in rest_blockfrost initialization.
  • Added and implemented handle_account_registrations_blockfrost, handle_account_delegations_blockfrost, and handle_account_mirs_blockfrost to handlers/accounts.rs.

Notes:

  • The registrations endpoint currently returns 0 for the amount field as this data isn't included in the certificate message. I am still considering the best approach for handling this and am currently leaning towards moving the historical epoch stakes data from accounts_state to historical_accounts_state although this would require passing the per stake address distribution on the message bus. Alternatively, we could rely on a second query in the rest handler to retrieve the account epoch stake from accounts_state under the assumption that spdd-retention-epochs is configured to store all epochs.

Next steps:

…ert-processing' into whankinsiv/reg-deleg-and-mir-rest-handlers
@whankinsiv
Copy link
Collaborator Author

Awaiting the review/merge of #272 before moving to ready for review.

Err(e) => {
return Ok(RESTResponse::with_text(
500,
&format!("Failed to encode pool ID: {e}"),
Copy link
Collaborator

@SupernaviX SupernaviX Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bigger change than I think makes sense in this PR, but in other projects I usually implement an API error to deal with the boilerplate of friendly REST error messages:

pub struct AppError(u16, anyhow::Error);
impl From<AppError> for RESTResponse {
    fn from(value: AppError) -> Self {
        Self::with_text(value.0, value.1.to_string())
    }
}
impl<E> From<E> for AppError
where
    E: Into<anyhow::Error>,
{
    fn from(value: E) -> Self {
        Self(500, value.into())
    }
}

It lets you lean on anyhow, and write calls to fallible methods in a much briefer way:

let pool_id = r.pool.to_bech32_with_hrp("pool").context("Failed to encode pool id")?;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #313 so that this refactor can be implemented in a follow up PR. This will clean up the module significantly.

Message::StateQueryResponse(StateQueryResponse::Accounts(
AccountsStateQueryResponse::NotFound,
)) => {
return Err(anyhow::anyhow!("Account not found"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this result in a 404 error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5eb101a to properly return 404 errors on NotFound. Thanks for catching this.

@whankinsiv
Copy link
Collaborator Author

Merging since all feedback has been addressed. I've created a follow up issue for Simon's suggestion about introducing an anyhow::Error wrapper.

@whankinsiv whankinsiv merged commit 779c262 into main Oct 29, 2025
2 checks passed
@whankinsiv whankinsiv deleted the whankinsiv/reg-deleg-and-mir-rest-handlers branch October 29, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants